package com.llc.spring.cloud.gateway.zuul.util;

import java.io.*;

/**
 * time 2018/6/22 16:33
 *
 * @author xiaojie.zhu <br>
 */
public class IOUtil {
    public static void close(Closeable closeable){
        if(closeable != null){
            try {
                closeable.close();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                closeable = null;
            }
        }
    }


    public static String toString(InputStream in , boolean close) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuffer sb = new StringBuffer();
        String line;
        while ((line = reader.readLine()) != null){
            sb.append(line);
        }

        if(close){
            IOUtil.close(in);
        }

        return sb.toString();
    }
}
